package com.open4cn.simulator.connect.com.handler;

import cn.hutool.json.JSONUtil;
import com.open4cn.simulator.core.connector.serialport.SerialPortHandlerContext;
import com.open4cn.simulator.core.connector.serialport.SerialPortOutboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-06-11 23:48
 */
public class WriteLogHandler extends SerialPortOutboundHandlerAdapter {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private String device;

    public WriteLogHandler(String device) {
        this.device = device;
    }

    @Override
    public void write(SerialPortHandlerContext ctx, Object msg) {
        logger.info("当前{}设备输出消息=>{}", device, JSONUtil.toJsonStr(msg));
        ctx.write(msg);
    }
}
